/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller.report;

import com.thienloc.omap.controller.BaseBean;
import com.thienloc.omap.entity.Sendsms;
import com.thienloc.omap.session.SendsmsFacade;
import com.thienloc.omap.util.JsfUtil;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@RequestScoped
public class SendsmsBean extends BaseBean implements Serializable {

    @EJB
    private SendsmsFacade facade;
    private List<Sendsms> list;
    private final Logger logger = LoggerFactory.getLogger(SendsmsBean.class);

    @PostConstruct
    public void init() {
        try {
            list = facade.findAll();
            Comparator<Sendsms> comparator = new Comparator<Sendsms>() {

                @Override
                public int compare(Sendsms o1, Sendsms o2) {
                    return o2.getSendtime().compareTo(o1.getSendtime());
                }
            };
            Collections.sort(list, comparator);
        } catch (Exception ex) {
            logger.error("[{}]: ", getUsername(), ex);
            JsfUtil.addErrorMessage("Lỗi", "Không lấy được thông tin MT từ DB");
        }
    }

    public List<Sendsms> getList() {
        return list;
    }
}
